/*

	IDevice.h
	
	Base class for graphics devices. Has derived
	versions for Linux and Windows.
	All operations related to graphics should go
	through the graphics device.
	
	Written by Sigurd Suhm 2009

*/

#ifndef _IDEVICE_H
#define _IDEVICE_H

// Includes
#include "EventHandler.h"		// Event handler class header

// Default window parameters
#define WIN_DEFAULT_WIDTH 800
#define WIN_DEFAULT_HEIGHT 600
#define WIN_DEFAULT_BPP 32

namespace EraAstral
{
	using namespace core;
	
	namespace core
	{
		// Class forward definitions
		class Logger;
	}

	namespace graphics
	{
		// IDevice graphics device interface	
		class IDevice : public IHasEvents
		{
			protected:
				// Log handler object that the device uses
				Logger		*m_logger;
				
				// Back buffer dimensions
				unsigned int	m_backBufferWidth, m_backBufferHeight;
				// Window dimensions
				unsigned int	m_winWidth, m_winHeight;

				// Sets SDL/OpenGL attributes
				void SetSDLGLAttributes();
				// Initializes OpenGL
				void InitOpenGL();
				// Initializes GLEW
				void InitGLEW();
				
				// Handle to frame buffer texture
				unsigned int	m_backBufferTex;
				// Handle to frame buffer object used for post processing
				unsigned int	m_frameBufferObject;
				// Handle to depth buffer for the frame buffer object
				unsigned int	m_depthBufferObject;
				
				// Flag determining if post processing should be used
				bool			m_usePostProcessing;
				// OpenGL shader program for post processing
				unsigned int	m_shaderProgram;
				// Bloom shader object
				unsigned int	m_bloomShader;

			public:
				// Default base constructor
				IDevice(core::Logger *logger);
				// Virtual base destructor
				virtual ~IDevice();
				
				// Clears the backbuffer and prepares the device for rendering
				virtual void BeginFrame() = 0;
				// Ends the frame and presents to the screen
				virtual void EndFrame() = 0;
				
				// Projection methods
				virtual void SetPerspective() = 0;
				virtual void SetOrtho() = 0;
				
				// Changes the resolution of the game
				virtual void ChangeResolution(unsigned int width, unsigned int height) = 0;
				// Toggle full screen mode
				virtual void ToggleFullScreen() = 0;
				// Handles OpenGL viewport resizing
				void ResizeGLView(int width, int height);
				// Changes the caption of the window
				virtual void SetWindowCaption(const char *caption) = 0;
			
				// Toggles grab input
				virtual void ToggleGrabInput() = 0;
				
				// Override from IHasEvents
				void ProcessEventSignal(const Event *event);
		};
		
		// Function for creating a graphics device
		extern IDevice *CreateDevice(core::Logger *logger);
	}
}

#endif		// _IDEVICE_H
